add this hook in your functions.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*-------------------------------------------------------------------------------------*/ | |
/* Login Hooks and Filters | |
/*-------------------------------------------------------------------------------------*/ | |
if( ! function_exists( 'custom_login_fail' ) ) { | |
function custom_login_fail( $username ) { | |
$referrer = $_SERVER['HTTP_REFERER']; // where did the post submission come from? | |
// if there's a valid referrer, and it's not the default log-in screen | |
if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') ) { | |
if ( !strstr($referrer,'?login=failed') ) { // make sure we don’t append twice | |
wp_redirect( $referrer . '?login=failed' ); // append some information (login=failed) to the URL for the theme to use | |
} else { | |
wp_redirect( $referrer ); | |
} | |
exit; | |
} | |
} | |
} | |
add_action( 'wp_login_failed', 'custom_login_fail' ); // hook failed login | |
if( ! function_exists( 'custom_login_empty' ) ) { | |
function custom_login_empty(){ | |
$referrer = $_SERVER['HTTP_REFERER']; | |
if ( strstr($referrer,get_home_url()) && $user==null ) { // mylogin is the name of the loginpage. | |
if ( !strstr($referrer,'?login=empty') ) { // prevent appending twice | |
wp_redirect( $referrer . '?login=empty' ); | |
} else { | |
wp_redirect( $referrer ); | |
} | |
} | |
} | |
} | |
add_action( 'authenticate', 'custom_login_empty'); |